
#include "NodeSentence.h"

using namespace npInterpreter;


NodeSentence::NodeSentence() : Node() // class inheritance
{
    //To initialize data member;
    this->direction = nullptr;
    this->action = nullptr;
    this->distance = nullptr;
}

NodeSentence::~NodeSentence()
{
    //To delete dynamic data member
    delete this->direction;
    delete this->action;
    delete this->distance;
}

NodeSentence::NodeSentence(const NodeSentence& cpy) : Node(cpy) // class inheritance
{
    //To copy data member
    this->direction = cpy.direction->clone();
    this->action = cpy.action->clone();
    this->distance = cpy.distance->clone();
}

NodeSentence& NodeSentence::operator=(const NodeSentence& asn)
{
    if (this == &asn)
    {
        return *this;
    }
    else
    {
        //To invoke base class operator=
        Node::operator=(asn);
        //To assign data member, note to delete dynamic member if exists.
        delete this->direction;
        delete this->action;
        delete this->distance;
        this->direction = asn.direction;
        this->action = asn.action;
        this->distance = asn.distance;

        return *this;
    }
}

NodeSentence::NodeSentence(NodeSentence&& mov) noexcept : Node(move(mov)) // class inheritance
{
    //to move data
    this->direction = mov.direction;
    this->action = mov.action;
    this->distance = mov.distance;
    mov.direction = nullptr;
    mov.action = nullptr;
    mov.distance = nullptr;
}

NodeSentence& NodeSentence::operator=(NodeSentence&& mva) noexcept
{
    if (this == &mva)
    {
        return *this;
    }
    else
    {
        //to inform base class to move data
        Node::operator=(move(mva));
        // to move data
        delete this->direction;
        delete this->action;
        delete this->distance;
        this->direction = mva.direction;
        this->action = mva.action;
        this->distance = mva.distance;
        mva.direction = nullptr;
        mva.action = nullptr;
        mva.distance = nullptr;

        return *this;
    }
}

NodeSentence* NodeSentence::clone() const
{
    //return new
    return new NodeSentence(*this);
}

//other constructors
NodeSentence::NodeSentence(Node* direction, Node* action, Node* distance)
{
    this->direction = direction;
    this->action = action;
    this->distance = distance;
}

//public methods
string NodeSentence::interpret() throw()
{
    return this->direction->interpret() + this->action->interpret() + this->distance->interpret();
}

//protected methods

//private methods

//others
